package com.ste.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.util.logging.Logger;

import com.ste.domain.Client;
import com.ste.server.command.Command;

public class ReadClient implements Runnable {
	private InputStream is;
	private Client client;
	private static Logger log = Logger.getLogger(ReadClient.class.getName());

	public ReadClient(InputStream is, Client client) {
		this.client = client;
		this.is = is;
	}

	@Override
	public void run() {
		BufferedReader ois = null;
		try {
			ois = new BufferedReader(new InputStreamReader(is));
			String message = null;
			while (true) {
				message = (String)ois.readLine();
				log.info("server in: " + message);
				client.getMessageQueue().put(new Command(client, message));
				
			}
		} catch (IOException e) {
			client.remove();
		} catch (InterruptedException e) {
		} finally {
			try {
				if (ois != null)
					ois.close();
			} catch (IOException e) {
			}
		}
	}

}
